# -*- coding: utf-8 -*-
"""
@Time    : 2024/10/22 13:39 
@Author  : ZhangShenao 
@File    : app.py
@Desc    : 应用启动入口
"""

from generator import generating
from indexer import indexing
from initiator import init_components
from retriever import retrieving

if __name__ == '__main__':
    # 初始化组件
    llm, embeddings, vector_store, reranker = init_components()
    print("============================================================")

    # 执行Indexing过程
    docs = indexing(file_path="./docs/企业数字化转型.pdf", vector_store=vector_store)
    print("============================================================")

    # 执行Retrieving过程
    query = "下面报告中涉及了哪几个行业的案例以及总结各自面临的挑战？"
    search_result = retrieving(query=query, docs=docs,
                               vector_store=vector_store, reranker=reranker, top_k=3)
    print(f"检索结果: {"\n".join([doc.page_content for doc in search_result])}")
    print("============================================================")

    # 执行Generating过程
    generating(query=query, docs=search_result, llm=llm)
    print("============================================================")

    print("RAG执行结束!")
